package main

/**
 * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
 *
 * @param target int整型
 * @param array int整型二维数组
 * @return bool布尔型
 */
func Find(target int, array [][]int) bool {
	// write code here
	rlen := len(array)
	if rlen == 0 {
		return false
	}
	clen := len(array[0])
	if clen == 0 {
		return false
	}
	r, c := 0, clen-1 // 右上角元素
	for r < rlen && c >= 0 {
		if target == array[r][c] {
			return true
		} else if target > array[r][c] {
			r++
		} else {
			c--
		}
	}
	return false
}

func main() {
	Find(7, [][]int{
		{1, 2, 8, 9},
		{4, 7, 10, 13}})
	Find(5, [][]int{
		{2, 4, 5, 8, 9, 12, 15, 18, 19, 21},
		{5, 7, 8, 10, 13, 16, 18, 20, 21, 24},
		{7, 9, 11, 12, 14, 19, 22, 24, 25, 28},
		{8, 10, 14, 17, 19, 22, 23, 27, 30, 32},
		{10, 12, 16, 20, 22, 25, 27, 30, 32, 35},
		{11, 13, 17, 23, 25, 28, 31, 32, 35, 38},
		{13, 16, 18, 24, 27, 30, 34, 36, 39, 40},
		{14, 19, 22, 26, 30, 32, 37, 39, 42, 45},
		{15, 21, 25, 29, 33, 34, 40, 43, 44, 47},
		{16, 23, 27, 32, 35, 37, 43, 45, 47, 50}})
}
